package com.urea.web.controller.urea;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.urea.system.domain.vo.TerminalVo;
import io.swagger.annotations.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.urea.common.annotation.Log;
import com.urea.common.core.controller.BaseController;
import com.urea.common.core.domain.AjaxResult;
import com.urea.common.enums.BusinessType;
import com.urea.system.domain.TerminalNotice;
import com.urea.system.service.ITerminalNoticeService;
import com.urea.common.utils.poi.ExcelUtil;
import com.urea.common.core.page.TableDataInfo;

/**
 * 终端预警日志Controller
 * 
 * @author liuzd
 * @date 2023-08-01
 */
@RestController
@RequestMapping("/terminal/notice")
@Api(tags = "终端信息处理/预警日志")
public class TerminalNoticeController extends BaseController
{
    @Autowired
    private ITerminalNoticeService terminalNoticeService;

    /**
     * 查询终端预警日志列表
     */
//    @PreAuthorize("@ss.hasPermi('terminal:notice:list')")
    @GetMapping("/list")
    @ApiOperation("信息列表(信息处理列表传status为0))")
    public TableDataInfo list(TerminalVo terminalNotice)
    {
        startPage();
        List<TerminalVo> list = terminalNoticeService.selectTerminalNoticeList(terminalNotice);
        return getDataTable(list);
    }

    /**
     * 导出终端预警日志列表
     */
    @PreAuthorize("@ss.hasPermi('terminal:notice:export')")
    @Log(title = "终端预警日志", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TerminalVo terminalNotice)
    {
        List<TerminalVo> list = terminalNoticeService.selectTerminalNoticeList(terminalNotice);
        ExcelUtil<TerminalVo> util = new ExcelUtil<TerminalVo>(TerminalVo.class);
        util.exportExcel(response, list, "终端预警日志数据");
    }

    /**
     * 获取终端预警日志详细信息
     */
    @PreAuthorize("@ss.hasPermi('terminal:notice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(terminalNoticeService.selectTerminalNoticeById(id));
    }

    /**
     * 新增终端预警日志
     */
    @PreAuthorize("@ss.hasPermi('terminal:notice:add')")
    @Log(title = "终端预警日志", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TerminalNotice terminalNotice)
    {
        return toAjax(terminalNoticeService.insertTerminalNotice(terminalNotice));
    }

    /**
     * 修改终端预警日志
     */
    @PreAuthorize("@ss.hasPermi('terminal:notice:edit')")
    @Log(title = "终端预警日志", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TerminalNotice terminalNotice)
    {
        return toAjax(terminalNoticeService.updateTerminalNotice(terminalNotice));
    }

    /**
     * 消息处理
     * @param vo 记录参数
     * @return 结果
     */
    @PostMapping("/handleMsg")
    @Log(title = "消息处理", businessType = BusinessType.INSERT)
    @ApiOperation("消息处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addNum",value = "添加数量"),
            @ApiImplicitParam(name = "msgHandleType",value = "消息处理标识 0 加满 1定量添加"),
            @ApiImplicitParam(name = "noticeId",value = "消息id"),
            @ApiImplicitParam(name = "id",value = "终端id"),
    })
    public AjaxResult handleMsg(@ApiParam(name = "处理消息",value = "TerminalVo") @RequestBody TerminalVo vo){
        terminalNoticeService.handleMsg(vo);
        return success();
    }

    /**
     * 删除终端预警日志
     */
    @PreAuthorize("@ss.hasPermi('terminal:notice:remove')")
    @Log(title = "终端预警日志", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(terminalNoticeService.deleteTerminalNoticeByIds(ids));
    }

}
